package com.jn.listtest_2;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.jn.listtest_2.adapter.MyArrayAdapter;
import com.jn.listtest_2.bean.Student;

import java.util.ArrayList;
import java.util.List;

public class ArrayAdapterActivity1 extends AppCompatActivity {
    private ListView mListView;
    private List<Student> mList;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listview);
        mListView = findViewById(R.id.listview);
        initData();
        MyArrayAdapter myArrayAdapter = new MyArrayAdapter(this, mList);
        mListView.setAdapter(myArrayAdapter);
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Student student = (Student) view.getTag();
                Log.e("test123", "=====" + student.toString());
            }
        });
    }

    private void initData() {
        mList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            Student student = new Student();
            student.setName("小明 " + i + " 号");
            student.setNumber("138888888" + i);
            mList.add(student);
        }
    }
}
